#ifndef AUDIODATAPROCESS_H
#define AUDIODATAPROCESS_H

#include <QObject>
#include <QThread>


class AudioDataProcess : public QObject
{
    Q_OBJECT
public:
    explicit AudioDataProcess(QObject *parent = nullptr);
    ~AudioDataProcess();
    enum AUDIO_PROCESS_STATUS{
        SUCCESS = 0,
        OPEN_FILE_FAILED,
        FILE_NOT_EXISTS,
        HANDLE_IS_NONE,
    };

private:
    QThread *thread;

    QVector<float *>audio_data;
    QVector<float *>ir_data;
    QVector<float *>result_data;


    QString audio_file_path;
    QString ir_file_path;

    int progress;
    int deal_sample_count;
    int deal_sample_max;

private:
    void convolution(const float *signal, int signal_length, const float *kernel, int kernel_length, float *result);
    AUDIO_PROCESS_STATUS open_audio_file(const QString &path,float **data_out,int *channels,int *sample_rate,int *frames);
    AUDIO_PROCESS_STATUS open_ir_file(const QString &path);
    void arm_conv_f32(
        const float * pSrcA,
        uint32_t srcALen,
        const float * pSrcB,
        uint32_t srcBLen,
        float * pDst);
    void convolution_fft(const float* signal_data, int signal_length, const float* kernel_data, int kernel_length, float* output);
private slots:
    void compute_progress(void);
public:
    AUDIO_PROCESS_STATUS set_audio_file_path(const QString &path);
    AUDIO_PROCESS_STATUS set_ir_file_path(const QString &path);
    int get_progress(void);

public slots:
    void create_file(void);
signals:
    void deal_progress(int progress);
};

#endif // AUDIODATAPROCESS_H
